﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：案件管理
 */


var acceptClick;
var dialogClose;
var bootstrap = function ($, learun) {
    "use strict";

    var companyId = request('companyId');
    var ztId = request('ztId');
    var kjnd = request('kjnd');

    var keyValue = '';
    var kjkmJ = request('kjkmJ');
    var kjkmD = request('kjkmD');
    var name = decodeURI(request('name'));

    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            $('#kjkmJ').lrformselect({
                placeholder: '请选择科目',
                layerUrl: config.webportal_server + 'pages/finance/kjkm/selectForm.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&controlName=kjkmJ' + '&needMx=1' + '&btnIndex=2' + '&access_token=' + config.getToken().access_token,
                layerUrlH: 500,
                dataUrl: config.base_server() + 'kjkms/getName?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&access_token=' + config.getToken().access_token,
                callback: function (kmItem) {
                    if (!kmItem || kmItem.value == '-1') {
                        kjkmJ = {};
                    } else {
                        kjkmJ = kmItem;
                    }
                }
            });
            $('#kjkmD').lrformselect({
                placeholder: '请选择科目',
                layerUrl: config.webportal_server + 'pages/finance/kjkm/selectForm.html?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&controlName=kjkmD' + '&needMx=1' + '&btnIndex=2' + '&access_token=' + config.getToken().access_token,
                layerUrlH: 500,
                dataUrl: config.base_server() + 'kjkms/getName?companyId=' + companyId + '&ztId=' + ztId + '&kjnd=' + kjnd + '&access_token=' + config.getToken().access_token,
                callback: function (kmItem) {
                    if (!kmItem || kmItem.value == '-1') {
                        kjkmD = {};
                    } else {
                        kjkmD = kmItem;
                    }
                }
            });
        },
        initData: function () {
            if (!!kjkmJ) {
                $("#kjkmJ").lrformselectSet(kjkmJ);
            }
            if (!!kjkmD) {
                $("#kjkmD").lrformselectSet(kjkmD);
            }
            if (!!name) {
                $("#name").val(name);
            }
            if (!!request('keyValue') && request('keyValue') != undefined && request('keyValue') != 'undefined') {
                keyValue = request('keyValue');
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var postData = $('#form').lrGetFormData(keyValue);
        postData["companyId"] = companyId;
        postData["ztId"] = ztId;
        postData["kjnd"] = kjnd;

        $.lrSaveForm(config.base_server() + 'pz_imports/saveOrUpdate?access_token=' + config.getToken().access_token + '&keyValue=' + keyValue, JSON.stringify(postData), function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
                dialogClose();
            }
        });
    };

    dialogClose = function () {
        try {
            var index = top.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            var $IsdialogClose = top.$("#layui-layer" + index).find('.layui-layer-btn').find("#IsdialogClose");
            var IsClose = $IsdialogClose.is(":checked");
            if ($IsdialogClose.length == 0) {
                IsClose = true;
            }
            if (IsClose) {
                top.layer.close(index);
            } else {
                location.reload();
            }
        } catch (e) {
            alert(e);
        }
    }

    page.init();
}